<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ncp.model.biz.bbs.ArticleProcess"%>
<%@page import="com.ncp.model.entity.comment.Articlebean"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
int nowPage=1;
int showPages=5;
int size=2;
ArticleProcess ap=new ArticleProcess();
int PageCount=ap.getArticclePageCount();
String now=request.getParameter("nowPage");
if(now!=null){
	nowPage=Integer.parseInt(now);
}
ArrayList<Articlebean> alist=ap.getArticle(nowPage);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showarticle.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  <link rel="stylesheet" href="css/common.css" type="text/css"/>
  <head>
  
  <body>
  <div id="allpage">
	<div id="nav">
		<ul id="nav_item">
			<li><a href="#">网站首页</a></li>
			<li><a href="#">关于我们</a></li>

			<li><a href="#">新闻动态</a></li>
			<li><a href="#">产品展示</a></li>
			<li><a href="#">产品订购</a></li>
			<li><a href="#">资料下载</a></li>
			<li><a href="#">联系方式</a></li>
		</ul>

	</div>
	<div style="width:800px; padding:0 40px; margin:0 auto;">
			<table width="100%" border="1">
			  <tr class="title">
			    <td><a href="#p">发表新主题</a></td>
			  </tr>
			  <tr class="head_title">
			    <td class="a common">标题</td>
			    <td class="b common">作者</td>
			    <td class="c common">浏览</td>
			    <td class="d common">回复</td>
			    <td class="e common">发帖时间</td>
			  </tr>
			 <style type="text/css">
			 tr{line-height:32px; height:32px;}
			 td{ padding:0 16px;}
			 .a{ width:150px;}
			 .b{ width:70px;}
			 .c{ width:70px;}
			 .d{ width:70px;}
			 .e{ width:360px;}
			 .one{}
			 .two{ background:#eee;}
			 a{ color:#000;}
			 a:hover{ color:#999;}
			 .head_title{ background:#eee;}
			 </style>
			 <%
			 for(int i=0;i<alist.size();i++){
				 Articlebean ab=alist.get(i);
				 if(i%2==0){
					%>
			   <tr class="one">
			    <td><a href="AdminReplyServlet?id=<%=ab.getId() %>"><%=ab.getTitle() %></a></td>
			    <td><%=ab.getUsername() %></td>
			    <td><%=ab.getClicks() %></td>
			    <td><%=ab.getReplycount(ab.getId()) %></td>
			    <td><%=ab.getPdate() %>by***/<a onclick="return confirm('确定要删除?')" href="AdminServlet?type=article&id=<%=ab.getId() %>">删除</a></td>
			  </tr>
					<%
				 }else{
					 %>
			  <tr class="two">
			    <td><a href="AdminReplyServlet?id=<%=ab.getId() %>"><%=ab.getTitle() %></a></td>
			    <td><%=ab.getUsername() %></td>
			    <td><%=ab.getClicks() %></td>
			    <td><%=ab.getReplycount(ab.getId()) %></td>
			    <td><%=ab.getPdate() %>/<a onclick="return confirm('确定要删除?')" href="AdminServlet?type=article&id=<%=ab.getId() %>">删除</a></td>
			  </tr>
					 <%
				 }
			 }
			 %>
			
			 <tr>
			    <td><div id="page">
					<ul>
					
					<% 
					if(nowPage>1){
						%><li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%= nowPage-1 %>" class="page">上一页</a></li><%
					}
					
					
					
						if(PageCount>=showPages){
							if(nowPage-size<=0){
								for(int i=1;i<=showPages;i++){
									%>
									
									<li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size<PageCount){
								for(int i=nowPage-size;i<=nowPage+size;i++){
									%>
									
									<li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size>=PageCount){
								for(int i=PageCount-showPages+1;i<=PageCount;i++){
									%>
									
									<li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
									<%
								}
							}
						}else if(PageCount<=showPages){
							for(int i=1;i<=PageCount;i++){
								%>
								<li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%=i %>" class="num" ><%=i %></a></li>
								<%
							}
						}
						
						if(nowPage<PageCount){
							%>
							<li><a href="pages/admin/bbs/showarticle.jsp?nowPage=<%=nowPage+1 %>" class="page" ">下一页</a></li>
							<%
						}
						%>
						<li>共<%= ap.getArticclePageCount()%>页&emsp;</li>
							
							<form action="pages/admin/bbs/showarticle.jsp" method="get">
							<li><input type="submit" value="跳到"/></li>
							<li><input id="skip" type="text" name="nowPage" style="width:30px; border:1px solid #CCC;" value="<%=nowPage %>"/></li>
							<li>页</li>
							</form>
					</ul>
		</div></td>
			  </tr>
			  <tr>
			    <td colspan="5">
			    <a name="p"></a>
			    <form action="ArticleProcessServlet" method="post">
			    <label>标题<input type="text" name="title" style="width:400px; height:30px; line-height:30px;margin-left:20px;border:1px solid #ccc;" /></label><br>
			    <label>内容<textarea name="cont" cols="45" rows="5" style="width:400px; margin-top:10px;line-height:30px;margin-left:20px;resize:none;border:1px solid #ccc;"></textarea></label>
			    <input type="submit" value="提交" style="cursor:pointer; background:#aaa; color:#fff; border:2px solid #ccc;" />
			     </form></td>
			  </tr>
			</table>
		</div>
</div>
</body>
</html>
